Skip to content

feat(codegen-kotlin): add KotlinWriter and move 14 small generators onto it - #658

Merged
dmealing merged 2 commits into
mainfrom
fm/mo-130-kt-writer-1
Nov 26, 2026
Merged

dmealing merged 2 commits into
mainfrom
fm/mo-130-kt-writer-1

Conversation

@dmealing

@dmealing dmealing commented Nov 26, 2026 •

Copy link
Copy Markdown
Member

What Changed

  • Adds KotlinWriter (server/java/codegen-kotlin/.../kotlin/writer/KotlinWriter.kt), a Kotlin dialect of the shared codegen-base CodeWriter (ADR-0063, contract in spec/code-writer.md). It collects and sorts imports, handles as aliases and keyword segments, escapes $ in strings, writes KDoc, and offers block, reopen and indented scoped forms. The shared fixtures/writer-conformance/ corpus gains ten kotlin cases, and KotlinLayoutRatchetTest keeps a shrink-only allowlist of emitters not yet converted.
  • Moves 14 small Kotlin generators onto the writer: names, filter allowlist, decimal and duration wire, validation issues, unknown body keys, validator, extractor, output parser, output prompt, render helper, stored proc, report export and requirement tests. Generated output changes in layout only: sorted imports in one group, lists that fit on one line, a trailing comma on broken lists, one-line KDoc for a single entry, no leading blank line in a block, and a blank line after the file header. Snapshot goldens are updated to match. Public methods that ejected copies call are kept.
  • Registers KotlinWriter, CodeWriter, Group and WriterOptions on eject.engineSurface.kotlin.engine, updates docs/CONFORMANCE.md, spec/code-writer.md and the 1.3.0 CHANGELOG, and adds the writer and ratchet tests to the Kotlin conformance lane (gate_conf_kotlin) in scripts/ci-local.sh. The pipeline's document step also added Kotlin writer pointers to docs/ports/kotlin.md and docs/features/own-your-codegen.md.

The golden diff is layout

Every changed snapshot under server/java/codegen-kotlin/src/test/resources/snapshots/ (24 files) changes layout only: imports sorted into one group, a list that fits written on one line, a trailing comma on a broken list, one-line KDoc for a single entry, no blank line at a block's start, and a blank line after a file header. No identifier, type, expression or literal value changes. The one exact-string test updated (KotlinReportRestSurfaceTest) moves for the same reasons.

Test exception (approved)

The gate's Test step returned inconclusive because it drove no live mvn metaobjects:generate run, and that exception was approved. The check it asked for is covered by the full Kotlin suite, which passed 683 of 683 locally on this head. That suite includes the snapshot goldens and the codegen-kotlin compile gate, which generates from fixtures/persistence-conformance/canonical/meta.fitness.json and compiles the output with KotlinCompilation, and CI reruns it. Also green locally: the maven-plugin eject contract tests, the TypeScript and Python writer-case runners, and scripts/ci-local.sh --only gates.

no-mistakes: 1 run.

Validation

Risk Assessment

✅ Low: The change adds a new writer and moves fourteen emitters onto it. Every golden diff is layout only: import order, list fitting, trailing commas, one-line KDoc, and blank lines at block starts and after headers. The fixed-content emitters are byte-identical apart from import order and the final newline, and the public engine surface that ejected copies call is kept.

Testing

Baseline scripts/ci-local.sh --affected --strict-toolchains passed. This turn ran the focused Kotlin writer conformance and layout ratchet tests in-process, and both passed (42 and 20 tests). These are unit-level runs, not live product runs, so no scenario is marked live. The user-facing behavior (regenerated Kotlin is layout-only and still compiles) was not driven end-to-end, so the verdict is inconclusive.

  • Live validation: ⚠️ inconclusive - 0 of 3 scenarios driven live against the product
Scenario Result Live Evidence
Kotlin writer conformance: core cases and kotlin dialect cases render as specified ⏸️ untested no Ran in-process as a unit test, not against a running product, so it cannot be marked live. Passing counts as supporting evidence only.
Kotlin layout ratchet: unconverted emitter allowlist may only shrink ⏸️ untested no Ran in-process as a unit test, not live. Ratchet comparison against the merge-base allowlist was not exercised against a real branch diff here.
Generate Kotlin from a fixture: output changes in layout only and still compiles ⏸️ untested no Needs the Maven plugin or codegen-kotlin fatjar built and run on fixtures/persistence-conformance. Not done within the time budget. Doable with mvn -am package plus metaobjects:generate in a scrat…
  • Outcome: ⚠️ 2 warnings across 1 run (7m36s)

Pipeline

Updates from git push no-mistakes

✅ **Intent** - passed

✅ No issues found.

✅ **Rebase** - passed

✅ No issues found.

✅ **Review** - passed

✅ No issues found.

⚠️ **Test** - 2 warnings
  • ⚠️ No live scenario driven. Generating Kotlin from a fixture needs the Maven plugin or fatjar built, which was out of budget. Layout-only golden diff and the compile of regenerated Kotlin are unverified live. Needs a live mvn metaobjects:generate run on fixtures/persistence-conformance to confirm.
  • ⚠️ live validation verdict: inconclusive (0 of 3 scenarios were driven live against the product); untested: Kotlin writer conformance: core cases and kotlin dialect cases render as specified, Kotlin layout ratchet: unconverted emitter allowlist may only shrink, Generate Kotlin from a fixture: output changes in layout only and still compiles
  • Live validation: ⚠️ inconclusive - 0 of 3 scenarios driven live against the product
Scenario Result Live Evidence
Kotlin writer conformance: core cases and kotlin dialect cases render as specified ⏸️ untested no Ran in-process as a unit test, not against a running product, so it cannot be marked live. Passing counts as supporting evidence only.
Kotlin layout ratchet: unconverted emitter allowlist may only shrink ⏸️ untested no Ran in-process as a unit test, not live. Ratchet comparison against the merge-base allowlist was not exercised against a real branch diff here.
Generate Kotlin from a fixture: output changes in layout only and still compiles ⏸️ untested no Needs the Maven plugin or codegen-kotlin fatjar built and run on fixtures/persistence-conformance. Not done within the time budget. Doable with mvn -am package plus metaobjects:generate in a scrat…
  • scripts/ci-local.sh --affected --strict-toolchains
  • mvn -o -q -pl codegen-kotlin -am -Dtest='KotlinWriterConformanceTest,KotlinLayoutRatchetTest,LayoutRatchetTest' -Dsurefire.failIfNoSpecifiedTests=false test in server/java: exit 0; surefire KotlinWriterConformanceTest 42 run, 0 fail; KotlinLayoutRatchetTest 20 run, 0 fail (reports fresh, 04:21)
  • Baseline from configured command scripts/ci-local.sh --affected --strict-toolchains already passed at target commit; not re-run, no source changed in this turn
✅ **Document** - passed

✅ No issues found.

✅ **Lint** - passed

✅ No issues found.

✅ **Push** - passed

✅ No issues found.

…ors on it

Adds the Kotlin dialect of the ADR-0063 code writer (KotlinWriter in
codegen-kotlin, on the shared codegen-base core), ten kotlin cases in
fixtures/writer-conformance/ beside the core ones, and a layout ratchet
(KotlinLayoutRatchetTest, using the Kotlin compiler's lexer) with a
shrink-only allowlist seeded with every file still typing its layout.

Converts the fourteen small generators onto the writer: names, filter
allowlist, decimal and duration wire, validation issues, unknown body keys,
validator, extractor, output parser, output prompt, render helper, stored
proc, report export and requirement tests. Their output changes in layout
only (sorted imports, a list that fits on one line, trailing commas, one-line
KDoc, no blank line at a block's start, a blank line after a file header);
the snapshot goldens move with it. The public methods an owned copy ejected
at an earlier version calls are kept.

The writer classes join the Kotlin eject engine surface; spec/code-writer.md,
the writer corpus README, docs/CONFORMANCE.md and CHANGELOG.md describe the
Kotlin dialect, and gate_conf_kotlin runs the writer and ratchet tests.
@dmealing
dmealing merged commit 2d83326 into main Nov 26, 2026
11 checks passed
@dmealing
dmealing deleted the fm/mo-130-kt-writer-1 branch November 26, 2026 09:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant